1
|
|
|
/** |
2
|
|
|
Copyright (C) 2018-2020 KANOUN Salim |
3
|
|
|
This program is free software; you can redistribute it and/or modify |
4
|
|
|
it under the terms of the Affero GNU General Public v.3 License as published by |
5
|
|
|
the Free Software Foundation; |
6
|
|
|
This program is distributed in the hope that it will be useful, |
7
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
8
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9
|
|
|
Affero GNU General Public Public for more details. |
10
|
|
|
You should have received a copy of the Affero GNU General Public Public along |
11
|
|
|
with this program; if not, write to the Free Software Foundation, Inc., |
12
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
13
|
|
|
*/ |
14
|
|
|
class PetCtCSVParser { |
15
|
|
|
|
16
|
|
|
constructor(csvFile){ |
17
|
|
|
this.csvFile = csvFile |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
parseCSV(){ |
21
|
|
|
let self = this |
22
|
|
|
|
23
|
|
|
return new Promise(function(complete, error) { |
24
|
|
|
Papa.parse(self.csvFile, {complete, error}); |
|
|
|
|
25
|
|
|
}).then(results => { |
26
|
|
|
self.papaResultArray = results.data |
27
|
|
|
}).then( () => { |
28
|
|
|
self._extractLineOfInterest() |
29
|
|
|
}); |
30
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
_extractLineOfInterest(){ |
34
|
|
|
let parsedCSV = this.papaResultArray |
35
|
|
|
|
36
|
|
|
for(let i = 0 ; i < parsedCSV.length ; i++){ |
37
|
|
|
//Search for empty line, the patient identification is just the line before |
38
|
|
|
if( parsedCSV[i].length>1 && parsedCSV[i][1].includes(" sum") ) { |
39
|
|
|
this.patientIdentificationLine = (i+1) |
40
|
|
|
} |
41
|
|
|
if( parsedCSV[i][0]=="SUVlo" ) { |
42
|
|
|
this.roiThresholdLine = (i+1) |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
console.log(this.papaResultArray) |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
getTmtvValue(){ |
49
|
|
|
return this.papaResultArray[(this.patientIdentificationLine - 1)][3] |
50
|
|
|
} |
51
|
|
|
getPatientId(){ |
52
|
|
|
return this.papaResultArray[this.patientIdentificationLine][13] |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
getAcquisitionDate(){ |
56
|
|
|
let dateString = this.papaResultArray[this.patientIdentificationLine][1].trim() |
57
|
|
|
let date = moment(dateString, "MMM D_YYYY").toDate(); |
58
|
|
|
return date |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
getSuvLow(){ |
62
|
|
|
return this.papaResultArray[this.roiThresholdLine][0] |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
getsuvHigh(){ |
66
|
|
|
return this.papaResultArray[this.roiThresholdLine][1] |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
isUseSUV(){ |
70
|
|
|
return Boolean(parseInt(this.papaResultArray[this.roiThresholdLine][4])) |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
isUseCT(){ |
74
|
|
|
return Boolean(parseInt(this.papaResultArray[this.roiThresholdLine][5])) |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
checkAcquisition(patientId, date){ |
78
|
|
|
return (this.getPatientId() == patientId && this.getAcquisitionDate().getTime() === date.getTime()) |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
checkTMTVThreshold(suvLo, suvHigh=100){ |
82
|
|
|
let checkSuvLo = true |
83
|
|
|
if(suvLo != null) checkSuvLo = (this.getSuvLow() == suvLo) |
|
|
|
|
84
|
|
|
return ( checkSuvLo && this.getsuvHigh()>=suvHigh && !this.isUseCT() && this.isUseSUV() ) |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.